import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import org.junit.Test;


/**
 * @最后修改人 yangnan
 * @最后修改时间 2021/1/5-12:00
 */
public class GeneralCodeStart {


  @Test
  public void testGenerator() {
    AutoGenerator autoGenerator = new AutoGenerator();

    //全局配置
    GlobalConfig globalConfig = new GlobalConfig();
    globalConfig.setAuthor("wuweigang")
      .setOutputDir("D:\\Data\\mybaties-general-tool\\src\\main\\java")//设置输出路径
      .setFileOverride(true)//设置文件覆盖
      .setIdType(IdType.INPUT)//设置主键生成策略
      .setServiceName("I%sService")//service接口的名称
      .setServiceImplName("%sServiceImpl")
      .setBaseResultMap(true)//基本结果集合
      .setBaseColumnList(true)//设置基本的列
      .setControllerName("%sController")
     ;

    //配置数据源
    DataSourceConfig dataSourceConfig = new DataSourceConfig();
    dataSourceConfig
//      .setDriverName("com.mysql.cj.jdbc.Driver")
      .setDriverName("oracle.jdbc.OracleDriver")
      .setUrl("jdbc:oracle:thin:@//192.168.1.xxx:1521/orcl")
      .setUsername("test").setPassword("CEoJYzRMZ6WwhF0S");


    //策略配置
    StrategyConfig strategyConfig = new StrategyConfig();
    strategyConfig.setCapitalMode(true)//设置全局大写命名
      .setNaming(NamingStrategy.underline_to_camel)//数据库表映射到实体的命名策略
      //.setTablePrefix("tbl_")//设置表名前缀
      .setInclude(new String[]{"CUSTOMER_ORDER","CUSTOMER_ORDER_ITEM"});

    //包名配置
    PackageConfig packageConfig = new PackageConfig();
    packageConfig
      .setParent("com.ienc.workflow")
      .setMapper("mapper")
      .setService("service")
      .setController("controller")
      .setEntity("entity")
      .setXml("mapper");

    autoGenerator.setGlobalConfig(globalConfig).setDataSource(dataSourceConfig)
      .setStrategy(strategyConfig).setPackageInfo(packageConfig);

    autoGenerator.execute();
  }

}
